package freecomm.study.notificationtest;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity
{
    /** Called when the activity is first created. */
    private Button sendBtn;
    private Button cancelBtn;
    private Notification n;
    private NotificationManager nm;
    private final static int ID = 1;

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        sendBtn = (Button) findViewById(R.id.sendBtn);
        cancelBtn = (Button) findViewById(R.id.cancelBtn);
        String service = NOTIFICATION_SERVICE;
        nm = (NotificationManager) getSystemService(service);
        n = new Notification();
        int icon = n.icon = R.drawable.ic_launcher;
        String tickerText = "Test Notification";
        long when = System.currentTimeMillis();
        n.icon = icon;
        n.tickerText = tickerText;
        n.when = when;
        sendBtn.setOnClickListener(new OnClickListener()
        {

            @Override
            public void onClick(View v)
            {
                // TODO Auto-generated method stub
                Intent intent = new Intent(MainActivity.this,
                        MainActivity.class);
                PendingIntent pi = PendingIntent.getActivity(MainActivity.this,
                        0, intent, 0);
                n.setLatestEventInfo(MainActivity.this, "Title", "My Content",
                        pi);
                nm.notify(ID, n);
            }
        });
        cancelBtn.setOnClickListener(new OnClickListener()
        {

            @Override
            public void onClick(View v)
            {
                // TODO Auto-generated method stub
                nm.cancel(ID);
            }
        });
    }
}